import { defineStore } from 'pinia'
import { getMenusAPI } from '@/api/index.js'

export const useMenuStore = defineStore('useMenuStore', {
    state: () => {
        return {
            collapse: true,
            hasroutes: false,
            menuList: [],
        }
    },
    getters: {
        getCollapse(state) {
            return state.collapse
        },
        getMenList(state) {
            return state.menuList
        }
    },
    // 也可以这样定义
    // state: () => ({ count: 0 })
    actions: {
        //收缩展开
        setCollapse() {
            this.collapse = !this.collapse
        },

        setHasroutes(val) {
            this.hasroutes = val
        },
        //获取路由

        async loadAuthRouters() {

            const res = await getMenusAPI()
            console.log("-0-0-0", res)
            this.menuList = res.menus
        },
        reset() {
            this.collapse = true
            this.hasroutes = false
            this.menuList = []
        }
    },

    persist: {
        enabled: true,
        strategies: [{
            storage: localStorage,
            key: 'menuStore',
            paths: ['menuList', 'collapse']
        }]

    }
})